package org.niux.aims.common.util;

import javax.servlet.ServletContext;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 * 
 * 文件名称：SpringUtil.java<br>
 * 摘    要：Spring工具类，用于包装和存储Spring上下文<br>
 * <br>
 * 当前版本：<br>
 * 作    者：李宇光 U.King Lli Email: <a href="mailto:ukinglli@gmail.com">ukinglli@gmail.com</a><br>
 * 完成日期：@since Oct 17, 2007<br>
 * <br>
 * 取代版本：<br>
 * 原作者  ：<br>
 * 完成日期：@since Oct 17, 2007<br>
 */
public class SpringUtil {
	//Spring上下文
	private static ServletContext servletContext;

    public static ServletContext getServletContext(){
        return servletContext;
    }
    public static void setServletContext(ServletContext ps_servletContext){
        servletContext = ps_servletContext;
    }
    
	public static WebApplicationContext getCxt() {
		return WebApplicationContextUtils
               .getRequiredWebApplicationContext(getServletContext());
	}
	
	/**
	 * 获取Spring Bean
	 */
	public static Object getBean(String beanId){
        try{
            return getCxt().getBean(beanId);
        }catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
        
	}
}